package kyssion.leetcode.num101_150;

import kyssion.leetcode.util.TreeNode;

public class code112_路径总和 {
    public boolean hasPathSum(TreeNode root, int sum) {
        return ans(root,sum,0);
    }

    private boolean ans(TreeNode root, int sum, int all) {
        if(root == null){
            return false;
        }else if(root.left==null&&root.right == null){
            all+=root.val;
            return all == sum;
        }else{
            all+=root.val;
            return ans(root.left,sum,all)||
                    ans(root.right,sum,all);
        }
    }
}
